<?php
/**
 * [LupMisNotAllowedSync]
 * 本代码为系统自动生成代码，请根据自己业务进行修改;
 * 生成时间 2022-02-15 20:59:20;
 * 版权所有 2020-2022 lizhongwen，并保留所有权利;
 * 说明: 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布;
 * 作者: 中文Lee;
 * 作者主页: http://www.lizhongwen.com;
 * 邮箱: 360811363@qq.com;
 * QQ: 360811363;
 */

namespace modules\sys\component;

use application\core\RedisUtil;
use modules\sys\mapper\ActionMapper;
use modules\sys\mapper\CatalogMapper;
use modules\sys\mapper\ConfigMapper;
use modules\sys\mapper\DictDataMapper;
use modules\sys\mapper\DictMapper;
use modules\sys\mapper\FieldMapper;
use modules\sys\mapper\PageMapper;
use modules\sys\mapper\RoleMapper;
use modules\sys\mapper\TableMapper;
use modules\sys\mapper\TreeMapper;

class GetCacheComponent
{

    public static function table()
    {
        if (REDIS_ENABLE) {
            $tableLists = RedisUtil::instance()->get('sys_table');
            $tableLists = !empty($tableLists) ? json_decode($tableLists,true) :TableMapper::lists();
        } else {
            $tableLists = TableMapper::lists();
        }
        return $tableLists;
    }

    public static function tree()
    {
        if (REDIS_ENABLE) {
            $treeLists = RedisUtil::instance()->get('sys_tree');
            $treeLists = !empty($treeLists) ? json_decode($treeLists,true) : TreeMapper::lists();
        }else{
            $treeLists = TreeMapper::lists();
        }
        return $treeLists;
    }

    public static function page()
    {
        if (REDIS_ENABLE) {
            $pageLists =  RedisUtil::instance()->get('sys_page');
            $pageLists = !empty($pageLists) ? json_decode($pageLists,true) : PageMapper::lists();

        }else{
            $pageLists = PageMapper::lists();
        }
        return $pageLists;
    }

    public static function action()
    {
        if (REDIS_ENABLE) {
            $actionLists = RedisUtil::instance()->get('sys_action');
            $actionLists = !empty($actionLists) ? json_decode($actionLists,true) : ActionMapper::lists();
        }else{
            $actionLists = ActionMapper::lists();
        }
        return $actionLists;
    }


    public static function role()
    {
        if (REDIS_ENABLE) {
            $roleLists = RedisUtil::instance()->get('sys_role');
            $roleLists = !empty($roleLists) ? json_decode($roleLists,true) : RoleMapper::lists();
        }else{
            $roleLists = RoleMapper::lists();
        }
        return $roleLists;
    }


    public static function field()
    {
        if (REDIS_ENABLE) {
            $fieldLists = RedisUtil::instance()->get('sys_field');
            $fieldLists = !empty($fieldLists) ? json_decode($fieldLists,true) : FieldMapper::lists();
        }else{
            $fieldLists = FieldMapper::lists();
        }
        return $fieldLists;
    }

    public static function dict()
    {
        if (REDIS_ENABLE) {
            $dictLists = RedisUtil::instance()->get('sys_dict');
            $dictLists = !empty($dictLists) ? json_decode($dictLists,true) : DictMapper::lists();
        }else{
            $dictLists = DictMapper::lists();
        }
        return $dictLists;
    }

    public static function dictData()
    {
        if (REDIS_ENABLE) {
            $dictDataLists = RedisUtil::instance()->get('sys_dict_data');
            $dictDataLists = !empty($dictDataLists) ? json_decode($dictDataLists,true) : DictDataMapper::lists();
        }else{
            $dictDataLists = DictDataMapper::lists();
        }
        return $dictDataLists;
    }

    public static function config()
    {
        if (REDIS_ENABLE) {
            $config = RedisUtil::instance()->get('sys_config');
            $config = !empty($config) ? json_decode($config,true) : ConfigMapper::query();
        }else{
            $config = ConfigMapper::query();
        }
        return $config;
    }

    public static function catalog()
    {
        if (REDIS_ENABLE) {
            $catalogLists = RedisUtil::instance()->get('sys_catalog');
            $catalogLists = !empty($catalogLists) ? json_decode($catalogLists,true) : CatalogMapper::lists();
        }else{
            $catalogLists = CatalogMapper::lists();
        }
        return $catalogLists;
    }
}